﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ChoDiaOc_HK_WPF.Models;

namespace ChoDiaOc_HK_WPF.Views.QuanLy {
    /// <summary>
    /// Interaction logic for DangNhap.xaml
    /// </summary>
    public partial class DangNhap : UserControl {
        public DangNhap() {
            InitializeComponent();
            dangNhapSource = (DANGNHAP)this.FindResource("dangNhapSource");
        }

        private DANGNHAP dangNhapSource;

        public DANGNHAP DangNhapSource {
            get { return dangNhapSource; }
            set { dangNhapSource = value; }
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e) {
           
            /*dangNhapSource.MatKhau = "khauit";
            dangNhapSource.TenDangNhap = "hoangkha";
            matKhauTextBox.Password = dangNhapSource.MatKhau;*/

        }

        private void btnDangNhap_Click(object sender, RoutedEventArgs e) {
            String role;
            if ((role = DatabaseWrapper.GetInstance().LogIn(dangNhapSource.TenDangNhap, matKhauTextBox.Password)) != "...") {
                MessageBox.Show("Đăng nhập thành công - Bạn đang có quyền " + role);
                btnNhapLai_Click(null, null);
                App.ManHinhChinh.DoLoggedIn(role);
            }
        }

        private void btnNhapLai_Click(object sender, RoutedEventArgs e) {
            tenDangNhapTextBox.Text = "";
            matKhauTextBox.Password = "";
        }
    }
}
